import 'package:flutter/material.dart';
import 'package:ytbusiness/config/yt_theme.dart';
import 'package:ytbusiness/utils/screen_adaptation.dart';
import 'package:ytbusiness/widgets/widgets.dart';

///新增发票
///
///
class AddInvoice extends StatefulWidget {
  @override
  _AddInvoiceState createState() => _AddInvoiceState();
}

///
class _AddInvoiceState extends State<AddInvoice> {
  TextEditingController _invoice = TextEditingController(); //发票抬头
  TextEditingController _identifyNumber = TextEditingController(); //识别号
  TextEditingController _accountNumber = TextEditingController(); //账号
  TextEditingController _locationAndPhone = TextEditingController(); //地址、电话
  TextEditingController _eMail = TextEditingController(); //邮箱
  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      behavior: HitTestBehavior.opaque,
      onTap: () {
        FocusScope.of(context).requestFocus(FocusNode());
      },
      child: Scaffold(
        appBar: customAppBar(context, title: "新增发票"),
        body: Container(
          color: Colors.white,
          margin: EdgeInsets.only(top: setWidth(10)),
          child: ListView(
            children: [
              _editItem(title: "发票抬头", controller: _invoice, hint: "请输入企业名称"),
              _editItem(
                  title: "纳税人识别号", controller: _identifyNumber, hint: "请输入税号"),
              _editItem(
                  title: "开户行及账号", controller: _accountNumber, hint: "请输入银行账户"),
              _editItem(
                  title: "地址、电话", controller: _locationAndPhone, hint: "请输入地址"),
              _editItem(title: "电子邮箱", controller: _eMail, hint: "请输入电子邮箱"),
              Row(
                mainAxisAlignment: MainAxisAlignment.end,
                children: [
                  Container(
                    margin:
                        EdgeInsets.only(top: setWidth(12), right: setWidth(15)),
                    child: Text(
                      "用于接收电子发票",
                      style: TextStyle(
                          color: Color(0xff989898), fontSize: setSp(13)),
                    ),
                  ),
                ],
              ),
              InkWell(
                onTap: () async {},
                child: Container(
                  margin: EdgeInsets.only(
                      left: setWidth(15),
                      right: setWidth(15),
                      top: setWidth(70)),
                  decoration: BoxDecoration(
                    color: YTTheme.theme,
                    borderRadius: BorderRadius.circular(setWidth(3)),
                  ),
                  alignment: Alignment.center,
                  height: setWidth(44),
                  child: Text(
                    '保存',
                    style: TextStyle(
                      color: Colors.white,
                      fontSize: setSp(18),
                    ),
                  ),
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }

  ///
  Widget _editItem(
      {String title, TextEditingController controller, String hint}) {
    return Column(
      children: [
        Container(
          color: Colors.white,
          padding: EdgeInsets.only(
              left: setWidth(15),
              right: setWidth(15),
              top: setWidth(20),
              bottom: setWidth(20)),
          child: Row(
            mainAxisAlignment: MainAxisAlignment.start,
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Container(
                width: setWidth(100),
                child: Text(
                  "$title:",
                  style:
                      TextStyle(color: Color(0xff323232), fontSize: setSp(15)),
                ),
              ),
              Expanded(
                child: TextField(
                  controller: controller,
                  textAlign: TextAlign.left,
                  style: TextStyle(fontSize: setSp(16)),
                  maxLines: null,
                  textInputAction: TextInputAction.done,
                  onSubmitted: (str) {},
                  onChanged: (val) {
                    setState(() {});
                  },
                  decoration: InputDecoration(
                    hintText: hint,
                    hintStyle: TextStyle(color: Color(0xff989898)),
                    contentPadding: EdgeInsets.only(
                      left: setWidth(15),
                    ),
                    isDense: true,
                    border: InputBorder.none,
                    focusedBorder: InputBorder.none,
                    enabledBorder: InputBorder.none,
                  ),
                ),
              ),
            ],
          ),
        ),
        Container(
          margin: EdgeInsets.only(left: setWidth(15), right: setWidth(15)),
          height: setWidth(0.5),
          color: Color(0xffF0F0F0),
        )
      ],
    );
  }
}
